var _common = require("../common");

function _defineProperty(t, i, o) {
    return i in t ? Object.defineProperty(t, i, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[i] = o, t;
}

var _global = global, api = _global.api, LIMIT = 20;

Component({
    data: {
        visitorSkeleton: !0,
        visitorLists: [ Array(8).fill({
            realname: "**",
            contents: [ {
                content: "**"
            } ]
        }) ]
    },
    created: function() {
        this.noMore = !1, this.offset = 0;
    },
    methods: {
        init: function(t) {
            this.data.visitorSkeleton && this.selectComponent("#skeleton1").create(this), this.loadList(!0, t);
        },
        onPullDownRefresh: function() {
            this.loadList(!0, wx.stopPullDownRefresh);
        },
        onReachBottom: function() {
            this.noMore || this.loadList(!1, null);
        },
        loadList: function(o, t) {
            var e = this, i = Promise.resolve();
            return o && (this.offset = 0, i = api.market.log.tickmsg({
                data: {
                    app: "xmp"
                }
            }).catch(function() {
                return {};
            })), i.then(function() {
                return api.market.log.lists({
                    data: {
                        limit: LIMIT,
                        offset: e.offset
                    },
                    complete: t
                });
            }).then(function(t) {
                var i = t.data.lists;
                return e.formatVisitorList(o, (0, _common.handleVisitorLists)(i));
            }), i;
        },
        formatVisitorList: function(t, i) {
            if (t) this.setData({
                visitorLists: [ i ],
                visitorSkeleton: !1
            }); else {
                var o = this.data.visitorLists.length;
                this.setData(_defineProperty({}, "visitorLists[".concat(o, "]"), i));
            }
            this.offset += LIMIT, this.noMore = i.length < LIMIT;
        },
        gotoChat: function(t) {
            (0, _common.gochat)(t, this);
        }
    }
});